#!/bin/bash
# Must be run from the base AORTA directory, eg,
# ./tools/auction_experiment all big_btr 7500 1

# TODO document different forms of commands...

COMMAND=$1

if [[ $COMMAND == "fifo" || $COMMAND == "all" ]]; then
  MAP=$2
  SPAWN_PER_HOUR=$3
  TRIAL=$4
  GENERATIONS="3"
  MAX_BUDGET="500"

  BASE="scenarios/${MAP}-${TRIAL}-fifo"

  if [[ $COMMAND == "fifo" ]]; then
    # The base-line... FCFS ordering
    ./experiment maps/${MAP}.map --spawn ${SPAWN_PER_HOUR} delay=3600 \
      generations=${GENERATIONS} lifetime=3600 budget=0-${MAX_BUDGET} \
      --out ${BASE}
  else
    ./tools/auction_experiment fifo ${MAP} ${SPAWN_PER_HOUR} ${TRIAL}
    ./tools/auction_experiment auction-sys ${BASE}
    ./tools/auction_experiment auction-no-sys ${BASE}
    ./tools/auction_experiment equal-sys ${BASE}
    ./tools/auction_experiment equal-no-sys ${BASE}
    ./tools/auction_experiment fixed-sys ${BASE}
    ./tools/auction_experiment fixed-no-sys ${BASE}
  fi
else
  # Transform an existing scenario into whatever is specified.
  INPUT=$2
  OUTPUT="${INPUT/-fifo/}-${COMMAND}"
  HEADER="${INPUT} --out ${OUTPUT}"
  NO_SYS="--cfg_wallets thruput_bonus=0 avail_capacity_threshold=0 capacity_bonus=0 dependency_rate=0 waiting_rate=0 ready_rate=0"

  case $COMMAND in
    # Regular auctions
    "auction-sys")
      ./experiment ${HEADER} --all_verts ordering=Auction
      ;;
    "auction-no-sys")
      ./experiment ${HEADER} ${NO_SYS} --all_verts ordering=Auction
      ;;

    # Every agent is weighted equally
    "equal-sys")
      ./experiment ${HEADER} --all_agents wallet=Static budget=1-1 \
        --all_verts ordering=Auction
      ;;
    "equal-no-sys")
      ./experiment ${HEADER} --all_agents wallet=Static budget=1-1 ${NO_SYS} \
        --all_verts ordering=Auction
      ;;

    # Every agent always bids their priority without losing money
    "fixed-sys")
      ./experiment ${HEADER} --all_agents wallet=Static --all_verts \
        ordering=Auction
      ;;
    "fixed-no-sys")
      ./experiment ${HEADER} --all_agents wallet=Static ${NO_SYS} --all_verts \
        ordering=Auction
      ;;
    *)
      echo "Invalid command ${COMMAND}"
      ;;
  esac
  # TODO all one type of policy
fi
